﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using C1.Web.Wijmo.Controls.C1TreeView;

namespace FixedAssets.Module.BasicInformation
{
    public partial class FA_Department : System.Web.UI.Page
    {

        public static int iRecordCount;
        static int iPageCount;
        static int iPageIndex;
        FA_Server.FA_S_Department fa_s_d;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                fa_s_d = new FA_Server.FA_S_Department();
                DataTable dt= fa_s_d.DDT.DefaultView.ToTable(true,new string[]{"SCORPNAME","ParentId"});
                MasterGridView.DataSource = dt;
                MasterGridView.DataBind();
            }
        }
        protected void MasterGridView_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {

                GridView oGridView = (GridView)e.Row.FindControl("DetailGridView");
                if (oGridView != null)
                {
                    DataView dv = fa_s_d.DDT.DefaultView;
                    dv.RowFilter=" ParentId='" + MasterGridView.DataKeys[e.Row.RowIndex].Value + "'";
                    dv.Sort = "SDEPARTMENTCODE";
                    DataTable dt = dv.ToTable(true, new string[] { "SDEPARTMENTNAME", "SDEPARTMENTCODE" });
                    oGridView.DataSource = dt;
                    oGridView.DataBind();
                }
            }
        }

        protected void DetailGridView_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            GridView a = (GridView)sender;
            Response.Write("您要删除的记录是：<font color='red'>" +
                a.DataKeys[e.RowIndex].Value.ToString() +
                "</font>&nbsp;&nbsp;&nbsp;&nbsp;TODO：执行删除动作");
            // TODO：执行删除动作
        }
        protected void DetailGridView_RowCommand(object sender, GridViewCommandEventArgs e)
        {

        }
       
        //private void DataGridDataBind()
        //{
        //    iRecordCount = fa_s_d.DDT.Rows.Count;
        //    iPageCount = (int)Math.Ceiling(iRecordCount * 1.0 / this.DepartmentGrid.PageSize);
        //    if (iRecordCount == 0)
        //    {
        //        this.DepartmentGrid.CurrentPageIndex = 0;
        //    }
        //    else if (this.DepartmentGrid.CurrentPageIndex >= iPageCount)
        //    {
        //        this.DepartmentGrid.CurrentPageIndex = iPageCount - 1;
        //    }

        //    this.DepartmentGrid.DataSource = fa_s_d.DDT;
        //    this.DepartmentGrid.CurrentPageIndex = iPageIndex;
        //    this.DepartmentGrid.DataBind();
        //    NavigationStateChange();
        //}
        //private void NavigationStateChange()
        //{
        //    if (iPageCount <= 1)
        //    {
        //        this.LBtnFirst.Enabled = false;
        //        this.LBtnPrev.Enabled = false;
        //        this.LBtnNext.Enabled = false;
        //        this.LBtnLast.Enabled = false;
        //    }
        //    else
        //    {
        //        if (iPageIndex == 0)
        //        {
        //            this.LBtnFirst.Enabled = false;
        //            this.LBtnPrev.Enabled = false;
        //            this.LBtnNext.Enabled = true;
        //            this.LBtnLast.Enabled = true;
        //        }
        //        else if (iPageIndex == iPageCount - 1)
        //        {
        //            this.LBtnFirst.Enabled = true;
        //            this.LBtnPrev.Enabled = true;
        //            this.LBtnNext.Enabled = false;
        //            this.LBtnLast.Enabled = false;
        //        }
        //        else
        //        {
        //            this.LBtnFirst.Enabled = true;
        //            this.LBtnPrev.Enabled = true;
        //            this.LBtnNext.Enabled = true;
        //            this.LBtnLast.Enabled = true;
        //        }
        //    }

        //    if (iRecordCount == 0)
        //    {
        //        this.LtlPageCount.Text = "0";
        //        this.LtlPageIndex.Text = "0";
        //    }
        //    else
        //    {
        //        this.LtlPageCount.Text = iPageCount.ToString();
        //        this.LtlPageIndex.Text = (iPageIndex + 1).ToString();
        //    }

        //    this.LtlPageSize.Text = this.DepartmentGrid.PageSize.ToString();
        //    this.LtlRecordCount.Text = iRecordCount.ToString();
        //}

        //private void LBtnNavigation_Click(object sender, System.EventArgs e)
        //{
        //    LinkButton btn = (LinkButton)sender;
        //    switch (btn.CommandName)
        //    { 
        //        case "First":
        //            iPageIndex = 1;
        //            break;
        //        case "Prev":
        //            iPageIndex = iPageIndex - 1;
        //            break;
        //        case "Next":
        //            iPageIndex = iPageIndex +1;
        //            break;
        //        case "Last":
        //            iPageIndex = iPageCount - 1;
        //            break;
        //    }
        //    DataGridDataBind();
        //}

        //private void InitD()
        //{ 
        //this.LBtnFirst.Click+=new EventHandler(this.LBtnNavigation_Click);
        //this.LBtnPrev.Click += new EventHandler(this.LBtnNavigation_Click);
        //this.LBtnNext.Click += new EventHandler(this.LBtnNavigation_Click);
        //this.LBtnLast.Click += new EventHandler(this.LBtnNavigation_Click);
        //}
    }
}